import scala.concurrent._
import scala.concurrent.duration._
import ExecutionContext.Implicits.global

import java.net._;
import java.nio._;

import java.util._;

object Client extends App 
{
	var socket = new Socket("localhost", 5555);
    var out = new java.io.DataOutputStream(socket.getOutputStream());
    var in = new java.io.DataInputStream(socket.getInputStream());
    
    var go = true;
    
    while(go)
    {
	    print("Enter a number: ");
	    var r = Console.readInt();
	    
	    if (r == -99)
	    {
	      out.writeInt(r);
	      go = false;
	      in.close();
	      out.close();
	      socket.close();
	    }
	    else
	    {
		    out.writeInt(r);
		    println ("sent to server:" + r);
		    var r2 = in.readInt();
		    println("number from server: " + r2);
	    }
    }
    
    /*
    
    println ("sent to server:" + theInteger);
    
    var r = in.readInt();
    println ("read from server:" + r);
    
    out.writeInt(0)
    
    in.close();
    out.close();
    socket.close();
 
    */
}

/*
object main extends App {
  
  val p = new Point;
  p.x = 3;
  p.y = 4;	
  
  val s = "Hello"
  
  var z = new Array[Future[String]](500)
  
  var a = 0;
  for( a <- 0 to 499){
    z(a) = future {
	  s + " future!"
  	}
    
    z(a) onSuccess {
  		case msg => println(msg + a)
  	}
    
    //val f: Future[String] = future {
	//  s + " future!"
  	//}
  
  	//f onSuccess {
  	//	case msg => println(msg + a)
  	//}
  }
  
  println ("Point x location : " + p.max());
 
  for( a <- 0 to 499){
    Await.result(z(a), 0 nanos)
  }
  
  
  //val theInteger = Console.readInt();
  //val theString = Console.readLine();
  
  //println (theInteger);
  //println (theString);
  
	
}

class Point {
  var x = 0;
  var y = 0;
  
  def max(): Int = {
    if 
      (x > y) x
	else 
	  y
  }
}
*/